home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / MPW / MPW noweb 2.7 / examples / sharpline < prev    next >
Encoding:
Text File  |  1995-05-30  |  655 b   |  32 lines  |  [TEXT/MPS ]

  1. #!/bin/sh
  2. #
  3. # noweb filter to handle #line directives in noweb input
  4. #
  5. # sample usage:
  6. #
  7. #  preprocessor files | notangle -L -filter sharpline - > result.c
  8. #
  9.  
  10. nawk '
  11. BEGIN { linestart = 1 }
  12. /^(@nl|@index nl)$/ { linestart = 1; print; next }
  13. /^@text #line +[0-9]+$/ {
  14.   if (linestart)
  15.     printf "@line %d\n", $3
  16.   else
  17.     print
  18.   linestart = 0; next
  19. }
  20. /^@text #line +[0-9]+ +".*"$/ {
  21.   if (linestart) {
  22.     thisline = $3
  23.     sub(/^@text #line +[0-9]+ +/, "")
  24.     thisfile = substr($0, 2, length($0) - 2)
  25.     printf "@file %s\n@line %d\n", thisfile, thisline
  26.   } else
  27.     print
  28.   linestart = 0; next
  29. }
  30. /^@(text |quote )/ { linestart = 0 }
  31. { print }' "$@"
  32.